/**
 * @desc    blob文件下载
 * @param {Blob} fileData
 * @param {String} fileName 下载文件名称指定
 */
function blobDownload(fileData, flieType = 'xlsx', fileName = '未命名文件') {
	if (!fileData) {
		return;
	}
	let flieTypeObj = {};
	if (flieType === 'xlsx') {
		flieTypeObj.type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
	} else if (flieType === 'pdf') {
		flieTypeObj.type = 'application/pdf';
	} else if (flieType === 'doc') {
		flieTypeObj.type = 'application/msword';
	} else if (flieType === 'docx') {
		flieTypeObj.type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
	} else if (flieType === 'xls') {
		flieTypeObj.type = 'application/vnd.ms-excel';
	} else if (flieType === 'ppt') {
		flieTypeObj.type = 'application/vnd.ms-powerpoint';
	} else if (flieType === 'pptx') {
		flieTypeObj.type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
	}
	const blob = new Blob([fileData], flieTypeObj);
	const objectUrl = URL.createObjectURL(blob);
	const a = document.createElement('a');
	document.body.appendChild(a);
	a.setAttribute('style', 'display:none');
	a.setAttribute('href', objectUrl);
	// a.setAttribute('download', fileName || Date.parse(new Date()));
	a.setAttribute('download', fileName || (new Date()).toJSON());
	a.click();
	document.body.removeChild(a);
	// 释放URL地址
	URL.revokeObjectURL(objectUrl);
}

export { blobDownload };
